﻿
$(function () {
    ProcessTaskShow()
    
})
//成品信息(工序任务分特)
function ProcessTaskShow() {
    layui.use('layer', function () {
        var form = layui.form;
        var id = localStorage["processTaskId"]
        // 创建表格实例
        $.ajax({
            url: "/ProcessTask/LedgerInfoProcessTaskDetails",
            type: "get",
            data: {
                processTaskId: id,
            },
            success: function (data) {
                data = JSON.parse(data);
                console.log(data.data);
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                $("#processName").text(data.data.processName)
                $("#taskMumber").text(data.data.taskMumber)
                var name = data.data.taskStatus == 1 ? "未开始" : data.data.taskStatus == 2 ? "进行中" : "已完成";
                $("#taskStatus").text(name)
                $("#productionLot").text(data.data.productionLot)
                $("#specifications").text(data.data.specifications)
                $("#size").text(data.data.size)
                $("#unit").text(data.data.unit)
                $("#priority").text(data.data.priority)
                if (data.data.priority == "紧急") {
                    $("#priority").css("color", "red");
                } else {
                    $("#priority").css("color", "green");
                }
                if (data.data.taskStatus ==1) {
                    $("#anjian").append(
                        '<button class="layui-btn layui-btn-primary layui-border"  onclick="quxiao()"> 取消</button >' +
                        '<button type="button" class="layui-btn layui-bg-blue" onclick="kaigong()">开工</button>'
                    )
                }
                else {
                    $("#anjian").append( 
                        '<button class="layui-btn layui-btn-primary layui-border"  onclick="quxiao()"> 取消</button >'+
                        '<button type="button" class="layui-btn layui-bg-blue"  onclick="baogong()">报工</button>' +
                        '<button class="layui-btn layui-btn-primary layui-border"  onclick="wangong()"> 完工</button >'
                    )
                }
            }
        });
        fillForm()

    })
}
//工艺路线
function fillForm() {

    $.ajax({
        url: "/Craft/GetCraftBackFill",
        type: "get",
        data: {
            craftManageId: 5,
            token: localStorage.getItem("token")
        },
        success: function (data) {
            data = JSON.parse(data);
            console.log(data.data.craftManageName);
            console.log(data.data.craftManageName);
            $("#craftManageName1").text(data.data.craftManageName)
        }
    });
    $.ajax({
        url: "/Process/ProcessModel",
        type: "get",
        data: {
            id: 1,
        },
        success: function (data) {
            data = JSON.parse(data);
            console.log(data.data);
            $("#processNumebring1").text(data.data.processNumebring)
            $("#processName1").text(data.data.processName)
        }
    });
}

//取消
function quxiao() {
    location.href = "/ProcessTask/ProcessTaskShow";
}
//开工
function kaigong() {
   
    var  Id= localStorage["processTaskId"]
    console.log(Id);
    $.ajax({
        type: "Post",
        url: "/ProcessTask/LedgerInfoProcessTaskupdate",  // 替换为实际的后台删除数据接口地址
        data: { processTaskId: Id, taskStatus:2, token: localStorage.getItem("token") },
        success: function (res) {
            var res = JSON.parse(res)
            if (res.code == 1) {
                layer.alert("修改成功");
                location.href = "/ProcessTask/ProcessTaskShow";  // 重新加载数据，刷新表格显示
            } else {
                layer.alert("修改失败");

            }
        },
        error: function () {
            layer.msg('修改失败，请稍后重试', {
                time: 2000,
                icon: 2
            });
        }
    });
}

//报工
function baogong() {
}

//完工
function wangong() {
    var processTaskId = localStorage["processTaskId"]
    $.ajax({
        type: "Post",
        url: "/ProcessTask/LedgerInfoProcessTaskupdate",  // 替换为实际的后台删除数据接口地址
        data: { processTaskId: processTaskId, taskStatus: 3, token: localStorage.getItem("token") },
        success: function (res) {
            var res = JSON.parse(res)
            if (res.code == 1) {
                layer.alert("修改成功");
                location.href = "/ProcessTask/ProcessTaskShow";  // 重新加载数据，刷新表格显示
            } else {
                layer.alert("修改失败");

            }
        },
        error: function () {
            layer.msg('修改失败，请稍后重试', {
                time: 2000,
                icon: 2
            });
        }
    });
}